using System;
using System.Collections.Generic;
using System.Text;

namespace Pampa.Common.Utils
{
    public class MultiDictionary<TKey, TValue>
    {
        private Dictionary<TKey, List<TValue>> innerDictionary;

        public MultiDictionary()
        {
            innerDictionary = new Dictionary<TKey, List<TValue>>();
        }

        public void Clear()
        {
            innerDictionary.Clear();
        }

        public void Add(TKey key, TValue value)
        {
            if (!innerDictionary.ContainsKey(key))
            {
                List<TValue> newList = new List<TValue>();
                newList.Add(value);
                innerDictionary.Add(key, newList);
            }
            else
            {
                if(!innerDictionary[key].Contains(value))
                {
                    innerDictionary[key].Add(value);
                }
            }
        }

        public void Remove(TKey key)
        {
            innerDictionary.Remove(key);
        }

        public List<TValue> this[TKey key]
        {
            get { return innerDictionary[key]; }
        }

        public bool ContainsKey(TKey key)
        {
            return innerDictionary.ContainsKey(key);
        }

        public int Count(TKey key)
        {
            if (innerDictionary.ContainsKey(key))
                return innerDictionary[key].Count;
            else
                return 0;
        }

        public Dictionary<TKey, List<TValue>>.Enumerator GetEnumerator()
        {
            return innerDictionary.GetEnumerator();
        }
    }
}
